package com.smsc.headend.connector.netty.initializer;

import cn.hutool.extra.spring.SpringUtil;
import com.smsc.headend.module.protocol.ProtocolType;
import io.netty.channel.ChannelInitializer;

public class ChannelInitializerFactory {

    public static ChannelInitializer getChannelInitializer(Long protocolId) {
        ProtocolType type = ProtocolType.getType(protocolId);
        ChannelInitializer channelInitializer = null;
        switch (type) {
            case DLMS_Gateway_Protocol:
            case DLMS_COSEM_46_Protocol:
            case DLMS_COSEM_47_Protocol:
                channelInitializer = new COSEMInitializer();
                break;
            case ANSI_C12_18_Protocol:
                channelInitializer = new AnsiInitializer();
                break;
            default:
                throw new IllegalStateException("no protocol initializer for protocol:" + protocolId);

        }
        SpringUtil.getConfigurableBeanFactory().autowireBean(channelInitializer);
        return channelInitializer;
    }

}
